package top.malaoshi.ctrl;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.Constants;
import top.malaoshi.model.Result;
import top.malaoshi.vo.JsonResult;
import top.malaoshi.service.LoginSrvImpl;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@RestController
//@CrossOrigin( allowCredentials = "true")
public class LoginCtrl {

    @Resource
    private LoginSrvImpl srv;

    @RequestMapping("/doLogin")
//    public Result doLogin(String phone, String password, HttpServletRequest request){
//        HttpSession session=request.getSession();
    public JsonResult doLogin(@RequestParam(value = "field1",required = false) String phone, @RequestParam(value = "field2",required = false) String password, HttpSession session){


        System.out.println(phone+"---"+password);

        Result res=srv.login(phone,password);

        JsonResult ret=new JsonResult();
        if(res.getCode()==0){
            session.setAttribute(Constants.USER_INFO,res.getData());
        }

        ret.setCode(res.getCode());
        ret.setMsg(res.getMsg());

        return ret;
    }
}
